
function Person(count) {
    this.count = count
}

Person.prototype.getAge = function () {
    return this.count
}

let p1 = new Person(150)
console.log(p1.getAge()) //150


let myNew = function (fn, ...args) {

    let constructor = fn

    if (typeof fn !== 'function') {
        return console.error('type error')
    }
    let newObject = Object.create(constructor.prototype)
    let result = constructor.apply(newObject, args)
    if (result && (typeof result === 'object' || typeof result === 'function')) {
        return result
    }
    return newObject
}

let p2 = myNew(Person, 150)

console.log(p1.getAge()) //

/***
 *  创建新对象 
 *  将fn的this指向创建的新对象 并执执行构造函数的代码（为新对象添加新属性）
 *  判断 函数返回类型  fn 优先 否则返回 新对象
 * 
 * 
 *  */ 